﻿namespace StarsAdmin.Core.Helpers;

public static class CheckHelper
{
    /// <summary>
    /// 验证是否非空
    /// </summary>
    /// <typeparam name="T">检查对象类型</typeparam>
    /// <param name="obj">检查对象</param>
    /// <returns></returns>
    /// <exception cref="ArgumentNullException"></exception>
    public static T NotNull<T>(this T? obj) where T : class
    {
        if (obj is null) throw new ArgumentNullException();
        return obj;
    }

    /// <summary>
    /// 验证是否非空
    /// </summary>
    /// <typeparam name="T">检查对象类型</typeparam>
    /// <param name="obj">检查对象</param>
    /// <param name="objName">为空的对象名称</param>
    /// <returns></returns>
    /// <exception cref="ArgumentNullException"></exception>
    public static T NotNull<T>(this T? obj, string? objName) where T : class
    {
        if (obj is null) throw new ArgumentNullException(objName);
        return obj;
    }
}